from math import comb

def qsum(n, k, p=0.1):
    q = 0
    for i in range(k + 1):
        q += comb(n, i) * (p ** i) * ((1 - p) ** (n - i))
    return q

def main():
    kk1 = []
    kk2 = []
    aerf1 = 0.05
    aerf2 = 0.1

    for n in range(20, 81, 15):
        k1 = 0
        k2 = 0
        while qsum(n, k1) < (1 - aerf1):
            k1 += 1
        while qsum(n, k2) < (1 - aerf2):
            k2 += 1
        kk1.append(k1)
        kk2.append(k2)
        print(f'95%的信度下,当样品总数为{n}时,认定零配件次品超过{k1},则拒绝')
        print(f'90%的信度下,当样品总数为{n}时,认定零配件次品不超过{k2},则接受')

if __name__ == "__main__":
    main()